define(["jquery"],function($){
	var quest = {};
	
	/**
	 * 数据处理(若不需要数据处理，可以不写)
	 */
    quest.formatData = function(obj){
    	if( !obj.maxWeek ) obj.maxWeek = 45;
    	if( !obj.minWeek ) obj.minWeek = 20;
    	var week = [];
    	for (var i = obj.minWeek; i <= obj.maxWeek; i++) {
    		week.push(i);
    	}
    	obj.list = [{
			"subunit":"周",
			"sublist":week
		},{
			"subunit":"天",
			"sublist":[0,1,2,3,4,5,6]
		}];
    	var len = obj.list.length;
    	obj.width = (100 / len) + "%";
    	for (var i = 0; i < len; i++) {
    		obj.list[i].textWidth = Number(obj.list[i].subunit.length) + Number(1) + 'em';
    	}
		return obj;
	}

	/**
	 * tpl模板
	 */
	quest.tpl = function(){
		return 	'<script id="tpl_question_gestation" type="text/html">'+
				'	<div {{if relationId}}relationId="{{relationId}}"{{/if}} class="qaCard-gestation qaCard form-group form-group-sm col-sm-{{length}} col-md-{{length}} grid-label-{{labelLength}}">'+
				'		<label class="control-label {{align}}">{{label}}</label>'+
				'   	<div class="control-input clearfix">'+
				'			{{if status == "default"}}'+
				'				{{each list as item i}}'+
				'					<div class="multiple" style="width:{{width}}">'+
				'						<select class="form-control validatebox" style="width:calc(100% - {{item.textWidth}} - 4px)" name="{{name}}" data-type="{{type}}" data-quesId="{{id}}" data-innDeCode="{{innDeCode}}" data-deCode="{{deCode}}" data-dataUnit="{{dataUnit}}" data-validate="{{validate}}" data-attention="{{attention}}">'+
				'							{{each item.sublist as value i}}'+
				'								<option value="{{value}}">{{value}}</option>'+
				'							{{/each}}'+
				'						</select>'+
				'						<span style="width:{{item.textWidth}}">{{item.subunit}}</span>'+
				'					</div>'+
				'				{{/each}}'+
				'			{{else if status == "readonly"}}'+
				'				{{each list as item i}}'+
				'					<div class="multiple" style="width:{{width}}">'+
				'						<select class="form-control validatebox" style="width:calc(100% - {{item.textWidth}} - 4px)" name="{{name}}" data-type="{{type}}" data-quesId="{{id}}" data-innDeCode="{{innDeCode}}" data-deCode="{{deCode}}" data-attention="{{attention}}" data-validate="{{validate}}" data-attention="{{attention}}" disabled>'+
				'							{{each item.sublist as value i}}'+
				'								<option value="{{value}}">{{value}}</option>'+
				'							{{/each}}'+
				'						</select>'+
				'						<span style="width:{{item.textWidth}}">{{item.subunit}}</span>'+
				'					</div>'+
				'				{{/each}}'+
				'			{{else if status == "disabled"}}'+
				'				{{each list as item i}}'+
				'					<div class="multiple" style="width:{{width}}">'+
				'						<select class="form-control validatebox" style="width:calc(100% - {{item.textWidth}} - 4px)" name="{{name}}" data-type="{{type}}" data-quesId="{{id}}" data-innDeCode="{{innDeCode}}" data-deCode="{{deCode}}" data-attention="{{attention}}" data-validate="{{validate}}" data-attention="{{attention}}" disabled>'+
				'							{{each item.sublist as value i}}'+
				'								<option value="{{value}}">{{value}}</option>'+
				'							{{/each}}'+
				'						</select>'+
				'						<span style="width:{{item.textWidth}}">{{item.subunit}}</span>'+
				'					</div>'+
				'				{{/each}}'+
				'			{{/if}}'+
				'		</div>'+
				'	</div>'+
				'</script>';
	}

	/**
	 * 赋值
	 */
	quest.setValue = function($dom,value){
		if( value ){
			var val = Number(value.quesValue);
			var week = parseInt(val / 7);
			var day = val % 7;
			$dom.eq(0).val(week);
			$dom.eq(1).val(day);
		}
	}

	/**
	 * 获取value（保存时，获取每个dom对应的答案）
	 */
	quest.getValue = function($dom,name){
		var dom = $dom.parents(".qaCard-gestation").find("select");
		var week = Number(dom.eq(0).val());
		var day = Number(dom.eq(1).val());
		var val = 7*week + day;
		var value = {};
		value.quesValue = val.toString();
		value.quesId = $dom.attr("data-quesId");
		value.deCode = $dom.attr("data-deCode");
		value.innDeCode = $dom.attr("data-innDeCode");
		var dataUnit = $dom.attr("data-dataUnit");
		if( dataUnit ) value.dataUnit = dataUnit;
		return value;
	}

	return quest;
});